import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as loginActions from '../../actions/login';
import * as messageActions from '../../actions/message'
import * as registerActions from '../../actions/register'
import * as logoutActions from '../../actions/logout'
import * as accountActions from '../../actions/account'

export function connectUser(Component) {
	class WrapComp extends React.Component {
		render() {
			return (
				<div><Component {...this.props} /></div>
			);
		}
	}
	 const mapStateToProps = (state) => ({
   		login: {
          session:state.login.session,
          isAuthenticated : state.login.isAuthenticated,
          statusText:state.login.statusText,
          authName:state.login.authName,
   		},
   		message: {
   		   isSending:state.message.isSending,
   		   isSended:state.message.isSended,
   		   count:state.message.count,
   		   statusText: state.message.statusText,
   		},
   		register: {
   		   session:state.register.session,
           isRegistered: state.register.isRegistered,
           isRegistering: state.register.isRegistering,
           statusText: state.register.statusText
   		},
   		logout: {
           session:state.logout.session,
           isLogouted:state.logout.isLogouted,
           isLogouting:state.logout.isLogouting,
           statusText: state.logout.statusText
   		},
   		account: {
   		   showed:state.account.showed,
   		   accountData:state.account.accountData,
   		   picshowed:state.account.picshowed,
   		   accountPic:state.account.accountPic,
   		}
  	});
  	const mapDispatchToProps = (dispatch) => ({
		loginActions: bindActionCreators(loginActions, dispatch),
		messageActions:bindActionCreators(messageActions,dispatch),
		registerActions:bindActionCreators(registerActions,dispatch),
		logoutActions:bindActionCreators(logoutActions,dispatch),
		accountActions:bindActionCreators(accountActions,dispatch),
  	});
	return connect(mapStateToProps, mapDispatchToProps)(WrapComp);
}